﻿using Microsoft.AspNetCore.Components;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.JSInterop;
using MudBlazor;
using Newtonsoft.Json.Linq;
using Plotly.Blazor;
using Plotly.Blazor.Interop;
using Plotly.Blazor.LayoutLib;
using Plotly.Blazor.Traces;
using Plotly.Blazor.Traces.ScatterLib;
using System;
using System.Text.Json;
using static BlazorSample.Pages.TreeTest;

namespace BlazorSample.Pages
{
    public partial class PlotlyBlazorLineChartTest1
    {
        private PlotlyChart plotlyChart;
        private Config config;
        private Plotly.Blazor.Layout layout;
        private IList<ITrace> data;
        private RelayoutEventData relayoutData;
        private RestyleEventData restyleData;

        public PlotlyBlazorLineChartTest1()
        {

        }

        private List<object> XAxisRange { get; set; } = new List<object> { 1, 4 };

        private async void Init()
        {
            await plotlyChart.SubscribeRelayoutEvent();
            await plotlyChart.SubscribeRestyleEvent();
        }

        public async void SelectedAction(IEnumerable<EventDataPoint> eventData)
        {
        }

        public async void RelayoutAction(RelayoutEventData eventData)
        {
            relayoutData = eventData;
            var rData = eventData.RawData.FirstOrDefault();
            var firstKey = rData.Key;
        }

        private async Task AddPictureData()
        {
            layout.Images.Clear();
            layout.Images.Add(new Plotly.Blazor.LayoutLib.Image()
            {
                X = 0,
                Y = 1,                           // 图片左上角位置（相对坐标，0~1）
                SizeX = (decimal)1,
                SizeY = (decimal)1,               // 图片大小（相对画布比例）
                //Opacity = (decimal)0.8,                          // 透明度
                Layer = Plotly.Blazor.LayoutLib.ImageLib.LayerEnum.Above,                         // 图片显示在图表上方
                Name = "image",
                Sizing = Plotly.Blazor.LayoutLib.ImageLib.SizingEnum.Stretch,
                Visible = true,
                XRef = "paper",
                YRef = "paper",
                Source = "",
            });
            plotlyChart.Relayout(CancellationToken.None);
        }
    }
}
